package com.kingland.Weidezhan.Service;

import com.kingland.Weidezhan.mapper.UserModelMapper;
import com.kingland.Weidezhan.model.UserModel;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class UserService implements UserServiceimpl{
    private UserModelMapper userModelMapper;
    private PasswordEncoder passwordEncoder;
    public  UserService(UserModelMapper userModelMapper, PasswordEncoder passwordEncoder){
        this.userModelMapper=userModelMapper;
        this.passwordEncoder=passwordEncoder;
    }
    @Override
    public UserModel addUser(UserModel userModel) {
        userModel.setPassword(
                this.passwordEncoder.encode(userModel.getPassword())
        );
        this.userModelMapper.insert(userModel);
        return userModel;
    }
}
